#include <bits/stdc++.h>
using namespace std;
int a[105];
int main(){
    a[1] = 1, a[2] = 1, a[3] = 1, a[4] = 1;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        string s;
        cin >> s;
        a[1] = 1, a[2] = 1, a[3] = 1, a[4] = 1;
        for (int j = 0; j < s.size(); j++){
            if (s[j] > '1') a[1] = 0;
            if (s[j] > '7') a[2] = 0;
            if (s[j] > '9') a[3] = 0;
            if (s[j] > 'F') a[4] = 0;
        }
        cout << a[1] << " " << a[2] << " " << a[3] << " " << a[4] << endl;
    }
    return 0;
}